// ----------------------------------------------------------------------------
// serialize_scalar_value.h
// ----------------------------------------------------------------------------
#pragma once
#include <fw/base/core/stdinteger.h>

namespace fw
{
	class ByteReader;
	class ByteWriter;
	
	class SerializeScalarValue
	{
	private:
		enum Type
		{
			kZero,
			kInt,
			kFloat,
		}; // enum Type
		
		Type			m_type;
		
		union
		{
			double		f64;
			int64_t		i64;
		}				m_value;
		
	public:
		SerializeScalarValue();
		
		static SerializeScalarValue Float		(double  value);
		static SerializeScalarValue Int			(int64_t value);
		static SerializeScalarValue Zero		();
		
		double						AsFloat		() const;
		int64_t						AsInt		() const;
		
		bool						operator==	(const SerializeScalarValue& other) const;
		bool						operator!=	(const SerializeScalarValue& other) const;
		
		bool						IsZero		() const
		{
			return (m_type == kZero) ? true : false;
		}
		
		void						Write		(ByteWriter& writer) const;
		static SerializeScalarValue	Read		(ByteReader& reader);
		
		uint64_t					GetChecksum	(uint64_t basis) const;
		
	}; // class SerializeScalarValue
	
} // namespace fw
